package logic

import (
	util "CampusCloudAid/pkg/captchaStore"
	"image/color"

	"github.com/mojocn/base64Captcha"
)

// 使用redis作为store
var store = util.RedisStore{}

// CaptMake 生成验证码
func CaptMake() (id, b64s, answer string) {
	var driver base64Captcha.Driver
	var driverString base64Captcha.DriverString
	// 配置验证码信息
	captchaConfig := base64Captcha.DriverString{
		Height:          60,
		Width:           200,
		NoiseCount:      0,
		ShowLineOptions: 0 | 0, //直线曲线个数
		Length:          1,     //长度
		Source:          "1",
		BgColor: &color.RGBA{
			R: 100,
			G: 102,
			B: 214,
			A: 0,
		},
		//	captchaConfig := base64Captcha.DriverString{
		//	Height:          60,
		//	Width:           200,
		//	NoiseCount:      0,
		//	ShowLineOptions: 2 | 4,
		//	Length:          4,
		//	Source:          "1234567890qwertyuioplkjhgfdsazxcvbnm",
		//	BgColor: &color.RGBA{
		//	R: 3,
		//	G: 102,
		//	B: 214,
		//	A: 125,
		//},

	}
	driverString = captchaConfig
	driver = driverString.ConvertFonts()
	captcha := base64Captcha.NewCaptcha(driver, store)
	lid, lb64s, ans, _ := captcha.Generate()
	return lid, lb64s, ans
}

// CaptVerify 验证captcha是否正确
func CaptVerify(id string, capt string) bool {
	if store.Verify(id, capt, true) {
		return true
	} else {
		return false
	}

}
